package com.dili.dd.gpi.service.impl;

import com.dili.dd.gpi.domain.EventParam;
import com.dili.dd.gpi.domain.EventParamExample;
import com.dili.dd.gpi.mapper.EventParamMapper;
import com.dili.dd.gpi.service.DmaEventParamService;
import com.dili.dd.gpi.util.spring.DataSourceLookupKey;
import com.dili.dd.gpi.util.spring.RequireDataSource;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by 思思君 on 2015/10/20.
 */
@Service
public class DmaEventParamServiceImpl implements DmaEventParamService
{
    @SuppressWarnings("SpringJavaAutowiringInspection")
    @Resource
    private EventParamMapper eventParamMapper;

    @Override
    @RequireDataSource(key = DataSourceLookupKey.DMA_DATASOURCE)
    public int createEevntParam(EventParam eventParam)
    {
        return eventParamMapper.insertSelective(eventParam);
    }

    @Override
    @RequireDataSource(key = DataSourceLookupKey.DMA_DATASOURCE)
    public List<EventParam> getEventParamsByEevntId(String eventId)
    {
        EventParamExample example = new EventParamExample();
        example.createCriteria().andEventIdEqualTo(eventId);
        return eventParamMapper.selectByExample(example);
    }

    @Override
    @RequireDataSource(key = DataSourceLookupKey.DMA_DATASOURCE)
    public int deleteEventParamById(Integer id)
    {
        return eventParamMapper.deleteByPrimaryKey(id);
    }

    @Override
    @RequireDataSource(key = DataSourceLookupKey.DMA_DATASOURCE)
    public int updateEventParam(EventParam eventParam)
    {
        return eventParamMapper.updateByPrimaryKeySelective(eventParam);
    }

    @Override
    @RequireDataSource(key = DataSourceLookupKey.DMA_DATASOURCE)
    public List<EventParam> getEventParamByName(String paramName, String eventId)
    {
        EventParamExample example = new EventParamExample();
        example.createCriteria().andParamNameEqualTo(paramName).andEventIdEqualTo(eventId);
        return eventParamMapper.selectByExample(example);
    }

    @Override
    @RequireDataSource(key = DataSourceLookupKey.DMA_DATASOURCE)
    public EventParam getEventParamById(Integer id)
    {
        return eventParamMapper.selectByPrimaryKey(id);
    }
}
